package org.directfire.player.model;


import org.directfire.player.DirectFire;
import org.directfire.player.R;
import org.directfire.player.utils.DFException;
import android.os.Messenger;
/**
 *   Copyright (C) 2012 Alexey Kostrjitskiy mailto:alex@ipss.net
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * $Id: Model.java 22 2012-08-27 06:00:54Z alexeyvk@gmail.com $<br/>
 * $HeadURL: http://directfire.googlecode.com/svn/trunk/DirectFireAndroid/src/org/directfire/player/model/Model.java $<br/><br/>
 *
 * DirectFirePlayer MVC static model. */
public class Model
{
  /** private static Model instance  */
  private static Model instance = null;
	/** preferences file name*/
	public static final String PREFS_NAME = "directfire";
	/** default timeout used in TCP connection */
	public static int    timeout=7;

	/** Messenger for communicating with WebTaxiService. */
	private Messenger mService = null;
	/** noConnectivity boolean */
	private boolean noConnectivity=true;
	/** noConnectivity boolean */
	private boolean isDebug=true;
	/** hold current ApplicationActivity flow index */
  private int current_flow;
	/** hold state of the player */
  private int duckVolume=0;
	/** hold state of the player */
  private boolean isPlaying=false;
	/** hold state of the player */
  private boolean isPlayingWhenConnectionLoose=false;
  /** hold playing track name */
  private String trackName="";


  /** Default constructor protected to defeat instantiation.<br/>
   */
  protected Model(){ }

  /**
   * Prepare unique Model instance, created in first method call.
   * @return the only one Model instance.
   */
  public static Model getI(){
	if(instance == null)
	  instance = new Model();
	return instance;
  }

	/**
   * Frequently used tool method for creation of the {@link DFException} instance.
   *
   * @param e ancestor exception
   * @param code code of the DF exception
   */
  public DFException exception(Exception e, int code){
  	return new DFException(e, code);
  }
  
	/**
   * Frequently used tool method for creation of the {@link DFException} instance.
   *
   * @param t ancestor Throwable
   * @param code code of the DF exception
   */
  public DFException exception(Throwable t, int code){
  	return new DFException(t, code);
  }

  /**
   * Frequently used tool method for creation of the {@link DFException} instance.
   *
   * @param code code of the DF exception
   * @param text text of the DF exception
   */
  public DFException exception(int code, String text){
  	return new DFException(code, text);
  }

	/** @return DirectFireService messenger to communicating with service */

  public Messenger getmService() {
		return mService;
	}
  /** set  */
	/** @param mService DirectFireService messenger for communicating with service */
	public void setmService(Messenger mService) {
		this.mService = mService;
	}
  
	/** @return noConnectivity flag */
	synchronized public boolean isNoConnectivity() {
		return noConnectivity;
	}
	/** @param noConnectivity - set noConnectivity flag */
	public void setNoConnectivity(boolean noConnectivity) {
		this.noConnectivity = noConnectivity;
	}

	/** @return isDebug flag */	
	public boolean isDebug() {
		return isDebug;
	}
	/** @param noConnectivity - set isDebug flag */
	public void setDebug(boolean isDebug) {
		this.isDebug = isDebug;
	}

	/** @return current flow of the main activity */
	public int getCurrent_flow() {
		return current_flow;
	}
	/** @param current_flow - set indication of the current flow */
	public void setCurrent_flow(int current_flow) {
		this.current_flow = current_flow;
	}
	
	public int getDuckVolume() {
		return duckVolume;
	}

	public void setDuckVolume(int duckVolume) {
		this.duckVolume = duckVolume;
	}

	public boolean isPlaying() {
		return isPlaying;
	}

	public void setPlaying(boolean isPlaying) {
		this.isPlaying = isPlaying;
	}

	public boolean isPlayingWhenConnectionLoose() {
		return isPlayingWhenConnectionLoose;
	}

	public void setPlayingWhenConnectionLoose(boolean isPlayingWhenConnectionLoose) {
		this.isPlayingWhenConnectionLoose = isPlayingWhenConnectionLoose;
	}

	public String getTrackName() {
		return trackName;
	}

	public void setTrackName(String trackName) {
		this.trackName = trackName;
	}

	public String getFullTitle(){
		return !isPlaying ? 
				DirectFire.getContext().getResources().getString(R.string.app_name)+" "
					+ DirectFire.getContext().getResources().getString(R.string.versionName) : 
				trackName;  
	}
	
	/** @param clear all model data */
	public void clearAll() {
	}
}
